<?php
    
    class MPage{
        
        private $vars;
        
        public function __construct( $vars ){
            $this->vars = $vars;
        }
        
        public function getPageData(){
            
            try{
                
                $db = new LMysql();
                $db->connect();
                
                if(count($this->vars) == 1){
                    if(array_key_exists('template', $this->vars)){
                        $sql = "select id, name, author, description, img, link, date_format(datum, '%d.%m.%Y') datum from " . $this->vars['template'];
                        $db->prepare($sql);
                    }
                }
                else if(count($this->vars) == 2){
                    if(array_key_exists('template', $this->vars)){
                        if(array_key_exists('id', $this->vars)){
                            $sql = "select id, name, author, description, img, link, date_format(datum, '%d.%m.%Y') datum from " . $this->vars['template'] . " where id='" . $this->vars['id'] . "'";
                            $db->prepare($sql);
                        }
                    }
                }
                else if(count($this->vars) == 3){
                    if(array_key_exists('template', $this->vars)){
                        if(array_key_exists('id', $this->vars) && array_key_exists('src', $this->vars)){
                            $sql = "select id, name, img, source, link, author, description, date_format(datum, '%d.%m.%Y') datum from " . $this->vars['template'] . " where id='" . $this->vars['id'] . "'";
                            $db->prepare($sql);
                        }
                    }
                }
                
                $db->query();
                
                return $db->fetch('array');
                
            }
            catch(Exception $e){
                die($e->getMessage());
            }
            
        }
        
    }

?>